



<!doctype html>
<html lang="en" class="no-js">
  <head>

<style>
  h1, h2, h3 { color: #04A9F4; }
  pre { color: black !important; }
</style>


      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width,initial-scale=1">
      <meta http-equiv="x-ua-compatible" content="ie=edge">

        <meta name="description" content="Open source package for Survival Analysis modeling">


        <link rel="canonical" href="https://www.pysurvival.io/models/kernel_svm.html">


        <meta name="author" content="The PySurvival Team">


        <meta name="lang:clipboard.copy" content="Copy to clipboard">

        <meta name="lang:clipboard.copied" content="Copied to clipboard">

        <meta name="lang:search.language" content="en">

        <meta name="lang:search.pipeline.stopwords" content="True">

        <meta name="lang:search.pipeline.trimmer" content="True">

        <meta name="lang:search.result.none" content="No matching documents">

        <meta name="lang:search.result.one" content="1 matching document">

        <meta name="lang:search.result.other" content="# matching documents">

        <meta name="lang:search.tokenizer" content="[\s\-]+">

      <link rel="shortcut icon" href="../images/favicon.ico">
      <meta name="generator" content="mkdocs-1.0.4, mkdocs-material-4.0.2">



        <title>Kernel Survival SVM (API) - PySurvival</title>



      <link rel="stylesheet" href="../assets/stylesheets/application.982221ab.css">

        <link rel="stylesheet" href="../assets/stylesheets/application-palette.224b79ff.css">




        <meta name="theme-color" content="#2196f3">



      <script src="../assets/javascripts/modernizr.1f0bcf2b.js"></script>



        <link href="https://fonts.gstatic.com" rel="preconnect" crossorigin>
        <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=:300,400,400i,700|">
        <style>body,input{font-family:"","Helvetica Neue",Helvetica,Arial,sans-serif}code,kbd,pre{font-family:"","Courier New",Courier,monospace}</style>


    <link rel="stylesheet" href="../assets/fonts/material-icons.css">






  </head>



    <body dir="ltr" data-md-color-primary="blue" data-md-color-accent="purple">

    <svg class="md-svg">
      <defs>


          <svg xmlns="http://www.w3.org/2000/svg" width="416" height="448"
    viewBox="0 0 416 448" id="__github">
  <path fill="currentColor" d="M160 304q0 10-3.125 20.5t-10.75 19-18.125
        8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19 18.125-8.5
        18.125 8.5 10.75 19 3.125 20.5zM320 304q0 10-3.125 20.5t-10.75
        19-18.125 8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19
        18.125-8.5 18.125 8.5 10.75 19 3.125 20.5zM360
        304q0-30-17.25-51t-46.75-21q-10.25 0-48.75 5.25-17.75 2.75-39.25
        2.75t-39.25-2.75q-38-5.25-48.75-5.25-29.5 0-46.75 21t-17.25 51q0 22 8
        38.375t20.25 25.75 30.5 15 35 7.375 37.25 1.75h42q20.5 0
        37.25-1.75t35-7.375 30.5-15 20.25-25.75 8-38.375zM416 260q0 51.75-15.25
        82.75-9.5 19.25-26.375 33.25t-35.25 21.5-42.5 11.875-42.875 5.5-41.75
        1.125q-19.5 0-35.5-0.75t-36.875-3.125-38.125-7.5-34.25-12.875-30.25-20.25-21.5-28.75q-15.5-30.75-15.5-82.75
        0-59.25 34-99-6.75-20.5-6.75-42.5 0-29 12.75-54.5 27 0 47.5 9.875t47.25
        30.875q36.75-8.75 77.25-8.75 37 0 70 8 26.25-20.5
        46.75-30.25t47.25-9.75q12.75 25.5 12.75 54.5 0 21.75-6.75 42 34 40 34
        99.5z" />
</svg>

      </defs>
    </svg>
    <input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
    <input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
    <label class="md-overlay" data-md-component="overlay" for="__drawer"></label>

      <a href="#kernel-svm-model" tabindex="1" class="md-skip">
        Skip to content
      </a>


      <header class="md-header" data-md-component="header">
  <nav class="md-header-nav md-grid">
    <div class="md-flex">
      <div class="md-flex__cell md-flex__cell--shrink">
        <a href="https://www.pysurvival.io/" title="PySurvival" class="md-header-nav__button md-logo">

            <img src="../images/logo.ico" width="24" height="24">

        </a>
      </div>
      <div class="md-flex__cell md-flex__cell--shrink">
        <label class="md-icon md-icon--menu md-header-nav__button" for="__drawer"></label>
      </div>
      <div class="md-flex__cell md-flex__cell--stretch">
        <div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">

            <span class="md-header-nav__topic">
              PySurvival
            </span>
            <span class="md-header-nav__topic">
              Kernel Survival SVM (API)
            </span>

        </div>
      </div>

              <!-- Global site tag (gtag.js) - Google Analytics -->
              <script async src="https://www.googletagmanager.com/gtag/js?id=UA-136790579-1"></script>
              <script>
                window.dataLayer = window.dataLayer || [];
                function gtag(){dataLayer.push(arguments);}
                gtag('js', new Date());

                gtag('config', 'UA-136790579-1');
              </script>

      <div class="md-flex__cell md-flex__cell--shrink">

          <label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>

<div class="md-search" data-md-component="search" role="dialog">
  <label class="md-search__overlay" for="__search"></label>
  <div class="md-search__inner" role="search">
    <form class="md-search__form" name="search">
      <input type="text" class="md-search__input" name="query" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query" data-md-state="active">
      <label class="md-icon md-search__icon" for="__search"></label>
      <button type="reset" class="md-icon md-search__icon" data-md-component="reset" tabindex="-1">
        &#xE5CD;
      </button>
    </form>
    <div class="md-search__output">
      <div class="md-search__scrollwrap" data-md-scrollfix>
        <div class="md-search-result" data-md-component="result">
          <div class="md-search-result__meta">
            Type to start searching
          </div>
          <ol class="md-search-result__list"></ol>
        </div>
      </div>
    </div>
  </div>
</div>

      </div>

        <div class="md-flex__cell md-flex__cell--shrink">
          <div class="md-header-nav__source">





<a href="https://github.com/square/pysurvival/" title="Go to repository" class="md-source" >

    <div class="md-source__icon">
      <svg viewBox="0 0 24 24" width="24" height="24">
        <use xlink:href="#__github" width="24" height="24"></use>
      </svg>
    </div>

  <div class="md-source__repository">
    square/pysurvival
  </div>
</a>
          </div>
        </div>

    </div>
  </nav>
</header>

    <div class="md-container">




      <main class="md-main">
        <div class="md-main__inner md-grid" data-md-component="container">


              <div class="md-sidebar md-sidebar--primary" data-md-component="navigation">
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    <nav class="md-nav md-nav--primary" data-md-level="0">
  <label class="md-nav__title md-nav__title--site" for="__drawer">
    <a href="https://www.pysurvival.io/" title="PySurvival" class="md-nav__button md-logo">

        <img src="../images/logo.ico" width="48" height="48">

    </a>
    PySurvival
  </label>

    <div class="md-nav__source">





<a href="https://github.com/square/pysurvival/" title="Go to repository" class="md-source" >

    <div class="md-source__icon">
      <svg viewBox="0 0 24 24" width="24" height="24">
        <use xlink:href="#__github" width="24" height="24"></use>
      </svg>
    </div>

  <div class="md-source__repository">
    square/pysurvival
  </div>
</a>
    </div>

  <ul class="md-nav__list" data-md-scrollfix>






  <li class="md-nav__item">
    <a href="../index.html" title="Home" class="md-nav__link">
      Home
    </a>
  </li>







  <li class="md-nav__item">
    <a href="../installation.html" title="Installation" class="md-nav__link">
      Installation
    </a>
  </li>







  <li class="md-nav__item">
    <a href="../intro.html" title="Introduction to Survival Analysis" class="md-nav__link">
      Introduction to Survival Analysis
    </a>
  </li>







  <li class="md-nav__item">
    <a href="../math.html" title="The math of Survival Analysis" class="md-nav__link">
      The math of Survival Analysis
    </a>
  </li>







  <li class="md-nav__item md-nav__item--nested">

      <input class="md-toggle md-nav__toggle" data-md-toggle="nav-5" type="checkbox" id="nav-5">

    <label class="md-nav__link" for="nav-5">
      Tutorials
    </label>
    <nav class="md-nav" data-md-component="collapsible" data-md-level="1">
      <label class="md-nav__title" for="nav-5">
        Tutorials
      </label>
      <ul class="md-nav__list" data-md-scrollfix>







  <li class="md-nav__item">
    <a href="../tutorials/churn.html" title="Churn Prediction" class="md-nav__link">
      Churn Prediction
    </a>
  </li>







  <li class="md-nav__item">
    <a href="../tutorials/credit_risk.html" title="Credit Risk" class="md-nav__link">
      Credit Risk
    </a>
  </li>







  <li class="md-nav__item">
    <a href="../tutorials/employee_retention.html" title="Employee Retention" class="md-nav__link">
      Employee Retention
    </a>
  </li>







  <li class="md-nav__item">
    <a href="../tutorials/maintenance.html" title="Predictive Maintenance" class="md-nav__link">
      Predictive Maintenance
    </a>
  </li>


      </ul>
    </nav>
  </li>









  <li class="md-nav__item md-nav__item--active md-nav__item--nested">

      <input class="md-toggle md-nav__toggle" data-md-toggle="nav-6" type="checkbox" id="nav-6" checked>

    <label class="md-nav__link" for="nav-6">
      Models
    </label>
    <nav class="md-nav" data-md-component="collapsible" data-md-level="1">
      <label class="md-nav__title" for="nav-6">
        Models
      </label>
      <ul class="md-nav__list" data-md-scrollfix>







  <li class="md-nav__item md-nav__item--nested">

      <input class="md-toggle md-nav__toggle" data-md-toggle="nav-6-1" type="checkbox" id="nav-6-1">

    <label class="md-nav__link" for="nav-6-1">
      Cox Proportional Hazard
    </label>
    <nav class="md-nav" data-md-component="collapsible" data-md-level="2">
      <label class="md-nav__title" for="nav-6-1">
        Cox Proportional Hazard
      </label>
      <ul class="md-nav__list" data-md-scrollfix>







  <li class="md-nav__item">
    <a href="coxph.html" title="Standard CoxPH  (API)" class="md-nav__link">
      Standard CoxPH  (API)
    </a>
  </li>







  <li class="md-nav__item">
    <a href="nonlinear_coxph.html" title="DeepSurv/Nonlinear CoxPH (API)" class="md-nav__link">
      DeepSurv/Nonlinear CoxPH (API)
    </a>
  </li>







  <li class="md-nav__item">
    <a href="semi_parametric.html" title="Theory" class="md-nav__link">
      Theory
    </a>
  </li>


      </ul>
    </nav>
  </li>







  <li class="md-nav__item md-nav__item--nested">

      <input class="md-toggle md-nav__toggle" data-md-toggle="nav-6-2" type="checkbox" id="nav-6-2">

    <label class="md-nav__link" for="nav-6-2">
      Multi-Task Logistic Regression (MTLR)
    </label>
    <nav class="md-nav" data-md-component="collapsible" data-md-level="2">
      <label class="md-nav__title" for="nav-6-2">
        Multi-Task Logistic Regression (MTLR)
      </label>
      <ul class="md-nav__list" data-md-scrollfix>







  <li class="md-nav__item">
    <a href="linear_mtlr.html" title="Linear MTLR (API)" class="md-nav__link">
      Linear MTLR (API)
    </a>
  </li>







  <li class="md-nav__item">
    <a href="neural_mtlr.html" title="Neural MTLR (API)" class="md-nav__link">
      Neural MTLR (API)
    </a>
  </li>







  <li class="md-nav__item">
    <a href="mtlr_theory.html" title="Theory" class="md-nav__link">
      Theory
    </a>
  </li>


      </ul>
    </nav>
  </li>







  <li class="md-nav__item md-nav__item--nested">

      <input class="md-toggle md-nav__toggle" data-md-toggle="nav-6-3" type="checkbox" id="nav-6-3">

    <label class="md-nav__link" for="nav-6-3">
      Non-Parametric
    </label>
    <nav class="md-nav" data-md-component="collapsible" data-md-level="2">
      <label class="md-nav__title" for="nav-6-3">
        Non-Parametric
      </label>
      <ul class="md-nav__list" data-md-scrollfix>







  <li class="md-nav__item">
    <a href="kaplan_meier.html" title="Kaplan Meier (API)" class="md-nav__link">
      Kaplan Meier (API)
    </a>
  </li>







  <li class="md-nav__item">
    <a href="smooth_kaplan_meier.html" title="Smoothed Kaplan Meier (API)" class="md-nav__link">
      Smoothed Kaplan Meier (API)
    </a>
  </li>







  <li class="md-nav__item">
    <a href="non_parametric.html" title="Theory" class="md-nav__link">
      Theory
    </a>
  </li>


      </ul>
    </nav>
  </li>







  <li class="md-nav__item md-nav__item--nested">

      <input class="md-toggle md-nav__toggle" data-md-toggle="nav-6-4" type="checkbox" id="nav-6-4">

    <label class="md-nav__link" for="nav-6-4">
      Parametric
    </label>
    <nav class="md-nav" data-md-component="collapsible" data-md-level="2">
      <label class="md-nav__title" for="nav-6-4">
        Parametric
      </label>
      <ul class="md-nav__list" data-md-scrollfix>







  <li class="md-nav__item">
    <a href="parametric.html" title="Parametric models (API)" class="md-nav__link">
      Parametric models (API)
    </a>
  </li>







  <li class="md-nav__item">
    <a href="parametric_theory.html" title="Theory" class="md-nav__link">
      Theory
    </a>
  </li>


      </ul>
    </nav>
  </li>







  <li class="md-nav__item md-nav__item--nested">

      <input class="md-toggle md-nav__toggle" data-md-toggle="nav-6-5" type="checkbox" id="nav-6-5">

    <label class="md-nav__link" for="nav-6-5">
      Simulation
    </label>
    <nav class="md-nav" data-md-component="collapsible" data-md-level="2">
      <label class="md-nav__title" for="nav-6-5">
        Simulation
      </label>
      <ul class="md-nav__list" data-md-scrollfix>







  <li class="md-nav__item">
    <a href="simulations.html" title="Simulation models (API)" class="md-nav__link">
      Simulation models (API)
    </a>
  </li>







  <li class="md-nav__item">
    <a href="simulations_theory.html" title="Theory" class="md-nav__link">
      Theory
    </a>
  </li>


      </ul>
    </nav>
  </li>







  <li class="md-nav__item md-nav__item--nested">

      <input class="md-toggle md-nav__toggle" data-md-toggle="nav-6-6" type="checkbox" id="nav-6-6">

    <label class="md-nav__link" for="nav-6-6">
      Survival Forest
    </label>
    <nav class="md-nav" data-md-component="collapsible" data-md-level="2">
      <label class="md-nav__title" for="nav-6-6">
        Survival Forest
      </label>
      <ul class="md-nav__list" data-md-scrollfix>







  <li class="md-nav__item">
    <a href="conditional_survival_forest.html" title="Conditional Survival Forest (API)" class="md-nav__link">
      Conditional Survival Forest (API)
    </a>
  </li>







  <li class="md-nav__item">
    <a href="extra_survival_trees.html" title="Extra Survival Trees (API)" class="md-nav__link">
      Extra Survival Trees (API)
    </a>
  </li>







  <li class="md-nav__item">
    <a href="random_survival_forest.html" title="Random Survival Forest (API)" class="md-nav__link">
      Random Survival Forest (API)
    </a>
  </li>







  <li class="md-nav__item">
    <a href="survival_forest.html" title="Theory" class="md-nav__link">
      Theory
    </a>
  </li>


      </ul>
    </nav>
  </li>









  <li class="md-nav__item md-nav__item--active md-nav__item--nested">

      <input class="md-toggle md-nav__toggle" data-md-toggle="nav-6-7" type="checkbox" id="nav-6-7" checked>

    <label class="md-nav__link" for="nav-6-7">
      Survival SVM
    </label>
    <nav class="md-nav" data-md-component="collapsible" data-md-level="2">
      <label class="md-nav__title" for="nav-6-7">
        Survival SVM
      </label>
      <ul class="md-nav__list" data-md-scrollfix>







  <li class="md-nav__item">
    <a href="linear_svm.html" title="Linear Survival SVM (API)" class="md-nav__link">
      Linear Survival SVM (API)
    </a>
  </li>









  <li class="md-nav__item md-nav__item--active">

    <input class="md-toggle md-nav__toggle" data-md-toggle="toc" type="checkbox" id="__toc">




      <label class="md-nav__link md-nav__link--active" for="__toc">
        Kernel Survival SVM (API)
      </label>

    <a href="kernel_svm.html" title="Kernel Survival SVM (API)" class="md-nav__link md-nav__link--active">
      Kernel Survival SVM (API)
    </a>


<nav class="md-nav md-nav--secondary">





    <label class="md-nav__title" for="__toc">Table of contents</label>
    <ul class="md-nav__list" data-md-scrollfix>

        <li class="md-nav__item">
  <a href="#instance" title="Instance" class="md-nav__link">
    Instance
  </a>

</li>

        <li class="md-nav__item">
  <a href="#methods" title="Methods" class="md-nav__link">
    Methods
  </a>

</li>

        <li class="md-nav__item">
  <a href="#example" title="Example" class="md-nav__link">
    Example
  </a>

</li>





    </ul>

</nav>

  </li>







  <li class="md-nav__item">
    <a href="survival_svm.html" title="Theory" class="md-nav__link">
      Theory
    </a>
  </li>


      </ul>
    </nav>
  </li>


      </ul>
    </nav>
  </li>







  <li class="md-nav__item md-nav__item--nested">

      <input class="md-toggle md-nav__toggle" data-md-toggle="nav-7" type="checkbox" id="nav-7">

    <label class="md-nav__link" for="nav-7">
      Performance metrics
    </label>
    <nav class="md-nav" data-md-component="collapsible" data-md-level="1">
      <label class="md-nav__title" for="nav-7">
        Performance metrics
      </label>
      <ul class="md-nav__list" data-md-scrollfix>







  <li class="md-nav__item">
    <a href="../metrics/c_index.html" title="C-index" class="md-nav__link">
      C-index
    </a>
  </li>







  <li class="md-nav__item">
    <a href="../metrics/brier_score.html" title="Brier Score" class="md-nav__link">
      Brier Score
    </a>
  </li>


      </ul>
    </nav>
  </li>







  <li class="md-nav__item md-nav__item--nested">

      <input class="md-toggle md-nav__toggle" data-md-toggle="nav-8" type="checkbox" id="nav-8">

    <label class="md-nav__link" for="nav-8">
      Miscellaneous
    </label>
    <nav class="md-nav" data-md-component="collapsible" data-md-level="1">
      <label class="md-nav__title" for="nav-8">
        Miscellaneous
      </label>
      <ul class="md-nav__list" data-md-scrollfix>







  <li class="md-nav__item">
    <a href="../miscellaneous/activation_functions.html" title="Activation Functions" class="md-nav__link">
      Activation Functions
    </a>
  </li>







  <li class="md-nav__item">
    <a href="../miscellaneous/save_load.html" title="Saving/Loading models" class="md-nav__link">
      Saving/Loading models
    </a>
  </li>







  <li class="md-nav__item">
    <a href="../miscellaneous/tips.html" title="Tips for fitting models" class="md-nav__link">
      Tips for fitting models
    </a>
  </li>


      </ul>
    </nav>
  </li>


  </ul>
</nav>
                  </div>
                </div>
              </div>


              <div class="md-sidebar md-sidebar--secondary" data-md-component="toc">
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">

<nav class="md-nav md-nav--secondary">





    <label class="md-nav__title" for="__toc">Table of contents</label>
    <ul class="md-nav__list" data-md-scrollfix>

        <li class="md-nav__item">
  <a href="#instance" title="Instance" class="md-nav__link">
    Instance
  </a>

</li>

        <li class="md-nav__item">
  <a href="#methods" title="Methods" class="md-nav__link">
    Methods
  </a>

</li>

        <li class="md-nav__item">
  <a href="#example" title="Example" class="md-nav__link">
    Example
  </a>

</li>





    </ul>

</nav>
                  </div>
                </div>
              </div>


          <div class="md-content">
            <article class="md-content__inner md-typeset">


                  <a href="https://github.com/square/pysurvival/edit/master/docs/models/kernel_svm.md" title="Edit this page" class="md-icon md-content__icon">&#xE3C9;</a>


                <!-- # SVM models-->

<style>
  h1, h2, h3 { color: #04A9F4; }
</style>

<h1 id="kernel-svm-model">Kernel SVM model</h1>
<p>The Kernel SVM model available in PySurvival is an adaptation of the work of <a href="https://arxiv.org/abs/1611.07054">Sebastian Polsterl et al.</a>.</p>
<hr />
<h2 id="instance">Instance</h2>
<p>To create an instance, use <code>pysurvival.models.svm.KernelSVMModel</code>.</p>
<hr />
<h2 id="methods">Methods</h2>
<div class="admonition abstract">
<p class="admonition-title"> <code>__init__</code> - Initialization </p>
<div class="codehilite" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>KernelSVMModel(kernel = &quot;gaussian&quot;, scale=1., offset=0., degree=1.,
    auto_scaler = True)
</pre></div>

<p><strong>Parameters:</strong></p>
<ul>
<li>
<p><code>kernel</code>: <strong>str</strong> <em>(default="gaussian")</em> --
    The type of kernel used to fit the model. Here's the list
    of available kernels:</p>
<ul>
<li>Polynomial</li>
<li>Gaussian</li>
<li>Exponential</li>
<li>Tanh</li>
<li>Sigmoid</li>
<li>Rational Quadratic</li>
<li>Inverse Multiquadratic</li>
<li>Multiquadratic</li>
</ul>
</li>
<li>
<p><code>scale</code>: <strong>float</strong> <em>(default=1)</em> --
    Scale parameter of the kernel function</p>
</li>
<li>
<p><code>offset</code>: <strong>float</strong> <em>(default=0)</em> --
    Offset parameter of the kernel function</p>
</li>
<li>
<p><code>degree</code>: <strong>float</strong> <em>(default=1)</em> --
    Degree parameter of the polynomial/kernel function</p>
</li>
</ul>
</div>
<div class="admonition abstract">
<p class="admonition-title"> <code>fit</code> - Fit the estimator based on the given parameters</p>
<div class="codehilite" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>fit(X, T, E, with_bias = True, init_method=&#39;glorot_normal&#39;, lr = 1e-2,
    max_iter = 100, l2_reg = 1e-4, tol = 1e-3, verbose = True)
</pre></div>

<p><strong>Parameters:</strong></p>
<ul>
<li>
<p><code>X</code> : <strong>array-like</strong> --
    input samples; where the rows correspond to an individual sample and the columns represent the features <em>(shape=[n_samples, n_features])</em>.</p>
</li>
<li>
<p><code>T</code> : <strong>array-like</strong> --
    target values describing the time when the event of interest or censoring
    occurred.</p>
</li>
<li>
<p><code>E</code> : <strong>array-like</strong> --
    values that indicate if the event of interest occurred i.e.: E[i]=1
    corresponds to an event, and E[i] = 0 means censoring, for all i.</p>
</li>
<li>
<p><code>with_bias</code>: <strong>bool</strong> <em>(default=True)</em> --
    Whether a bias should be added </p>
</li>
<li>
<p><code>init_method</code> : <strong>str</strong> <em>(default = 'glorot_uniform')</em> --
    Initialization method to use. Here are the possible options:</p>
<ul>
<li><code>glorot_uniform</code>: <a href="http://jmlr.org/proceedings/papers/v9/glorot10a/glorot10a.pdf">Glorot/Xavier uniform initializer</a></li>
<li><code>he_uniform</code>: <a href="http://arxiv.org/abs/1502.01852">He uniform variance scaling initializer</a></li>
<li><code>uniform</code>: Initializing tensors with uniform (-1, 1) distribution</li>
<li><code>glorot_normal</code>: Glorot normal initializer,</li>
<li><code>he_normal</code>: He normal initializer.</li>
<li><code>normal</code>: Initializing tensors with standard normal distribution</li>
<li><code>ones</code>: Initializing tensors to 1</li>
<li><code>zeros</code>: Initializing tensors to 0</li>
<li><code>orthogonal</code>: Initializing tensors with a orthogonal matrix,</li>
</ul>
</li>
<li>
<p><code>lr</code>: <strong>float</strong> <em>(default=1e-4)</em> --
    learning rate used in the optimization</p>
</li>
<li>
<p><code>max_iter</code>: <strong>int</strong> <em>(default=100)</em> --
    maximum number of iterations in the Newton optimization</p>
</li>
<li>
<p><code>l2_reg</code>: <strong>float</strong> <em>(default=1e-4)</em> --
    L2 regularization parameter for the model coefficients</p>
</li>
<li>
<p><code>alpha</code>: <strong>float</strong> <em>(default=0.95)</em> --
    confidence level</p>
</li>
<li>
<p><code>tol</code>: <strong>float</strong> <em>(default=1e-3)</em> --
    tolerance for stopping criteria</p>
</li>
<li>
<p><code>verbose</code>: <strong>bool</strong> <em>(default=True)</em> --
    whether or not producing detailed logging about the modeling</p>
</li>
</ul>
<p><strong>Returns:</strong></p>
<ul>
<li>self : object</li>
</ul>
</div>
<div class="admonition abstract">
<p class="admonition-title"><code>predict_risk</code> - Predicts the risk score <script type="math/tex">r(x)</script>
</p>
<div class="codehilite" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>predict_risk(x, use_log=True)
</pre></div>

<p><strong>Parameters:</strong></p>
<ul>
<li>
<p><code>x</code> : <strong>array-like</strong> --
    input samples; where the rows correspond to an individual sample and the columns represent the features <em>(shape=[n_samples, n_features])</em>.
    x should not be standardized before, the model will take care of it</p>
</li>
<li>
<p><code>use_log</code>: <strong>bool</strong> <em>(default=False)</em> --
    whether or not appliying the log function to the risk values</p>
</li>
</ul>
<p><strong>Returns:</strong></p>
<ul>
<li><code>risk_score</code>: <strong>numpy.ndarray</strong> --
    array-like representing the prediction of the risk score</li>
</ul>
</div>
<hr />
<h2 id="example">Example</h2>
<p>Let's now see how to use the KernelSVMModel models on a <a href="simulations.html">simulation dataset generated from a parametric model</a>.</p>
<div class="codehilite" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #408080; font-style: italic">#### 1 - Importing packages</span>
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">pandas</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">pd</span>
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">matplotlib</span> <span style="color: #008000; font-weight: bold">import</span> pyplot <span style="color: #008000; font-weight: bold">as</span> plt
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">pysurvival.models.svm</span> <span style="color: #008000; font-weight: bold">import</span> KernelSVMModel
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">pysurvival.models.simulations</span> <span style="color: #008000; font-weight: bold">import</span> SimulationModel
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">pysurvival.utils.metrics</span> <span style="color: #008000; font-weight: bold">import</span> concordance_index
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.model_selection</span> <span style="color: #008000; font-weight: bold">import</span> train_test_split
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">scipy.stats.stats</span> <span style="color: #008000; font-weight: bold">import</span> pearsonr
<span style="color: #408080; font-style: italic"># %pylab inline # to use in jupyter notebooks</span>

<span style="color: #408080; font-style: italic">#### 2 - Generating the dataset from the parametric model</span>
<span style="color: #408080; font-style: italic"># Initializing the simulation model</span>
sim <span style="color: #666666">=</span> SimulationModel( survival_distribution <span style="color: #666666">=</span> <span style="color: #BA2121">&#39;Log-Logistic&#39;</span>,
                       risk_type <span style="color: #666666">=</span> <span style="color: #BA2121">&#39;square&#39;</span>,
                       censored_parameter <span style="color: #666666">=</span> <span style="color: #666666">1.1</span>,
                       alpha <span style="color: #666666">=</span> <span style="color: #666666">1.5</span>, beta <span style="color: #666666">=</span> <span style="color: #666666">4</span>)

<span style="color: #408080; font-style: italic"># Generating N Random samples</span>
N <span style="color: #666666">=</span> <span style="color: #666666">1000</span>
dataset <span style="color: #666666">=</span> sim<span style="color: #666666">.</span>generate_data(num_samples <span style="color: #666666">=</span> N, num_features <span style="color: #666666">=</span> <span style="color: #666666">4</span>)

<span style="color: #408080; font-style: italic"># Showing a few data-points</span>
dataset<span style="color: #666666">.</span>head(<span style="color: #666666">2</span>)
</pre></div>

<p>We can now see an overview of the data:</p>
<table>
<thead>
<tr>
<th>x_1</th>
<th>x_2</th>
<th>x_3</th>
<th>x_4</th>
<th>time</th>
<th>event</th>
</tr>
</thead>
<tbody>
<tr>
<td>13.234733</td>
<td>10.0</td>
<td>12.0</td>
<td>11.0</td>
<td>0.264510</td>
<td>1.0</td>
</tr>
<tr>
<td>4.694893</td>
<td>14.0</td>
<td>11.0</td>
<td>7.0</td>
<td>0.000026</td>
<td>1.0</td>
</tr>
</tbody>
</table>
<p>Pysurvival also displays the Base Survival function of the Simulation model:
<div class="codehilite" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">pysurvival.utils.display</span> <span style="color: #008000; font-weight: bold">import</span> display_baseline_simulations
display_baseline_simulations(sim, figure_size<span style="color: #666666">=</span>(<span style="color: #666666">20</span>, <span style="color: #666666">6</span>))
</pre></div>
<center><img src="images/kernel_svm_example_1.png" alt="PySurvival - Kernel SVM - Base Survival function of the Simulation model" title="PySurvival - Kernel SVM - Base Survival function of the Simulation model" width=100%, height=100%  /></center>
<center>Figure 1 - Base Survival function of the Simulation model</center></p>
<div class="codehilite" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #408080; font-style: italic">#### 3 - Splitting the dataset into training and testing sets</span>
<span style="color: #408080; font-style: italic"># Defining the features</span>
features <span style="color: #666666">=</span> sim<span style="color: #666666">.</span>features

<span style="color: #408080; font-style: italic"># Building training and testing sets #</span>
index_train, index_test <span style="color: #666666">=</span> train_test_split( <span style="color: #008000">range</span>(N), test_size <span style="color: #666666">=</span> <span style="color: #666666">0.2</span>)
data_train <span style="color: #666666">=</span> dataset<span style="color: #666666">.</span>loc[index_train]<span style="color: #666666">.</span>reset_index( drop <span style="color: #666666">=</span> <span style="color: #008000">True</span> )
data_test  <span style="color: #666666">=</span> dataset<span style="color: #666666">.</span>loc[index_test]<span style="color: #666666">.</span>reset_index( drop <span style="color: #666666">=</span> <span style="color: #008000">True</span> )

<span style="color: #408080; font-style: italic"># Creating the X, T and E input</span>
X_train, X_test <span style="color: #666666">=</span> data_train[features], data_test[features]
T_train, T_test <span style="color: #666666">=</span> data_train[<span style="color: #BA2121">&#39;time&#39;</span>]<span style="color: #666666">.</span>values, data_test[<span style="color: #BA2121">&#39;time&#39;</span>]<span style="color: #666666">.</span>values
E_train, E_test <span style="color: #666666">=</span> data_train[<span style="color: #BA2121">&#39;event&#39;</span>]<span style="color: #666666">.</span>values, data_test[<span style="color: #BA2121">&#39;event&#39;</span>]<span style="color: #666666">.</span>values


<span style="color: #408080; font-style: italic">#### 4 - Creating an instance of the SurvivalSVM model and fitting the data.</span>
svm_model <span style="color: #666666">=</span> KernelSVMModel(kernel<span style="color: #666666">=</span><span style="color: #BA2121">&#39;Gaussian&#39;</span>, scale<span style="color: #666666">=0.25</span>)
svm_model<span style="color: #666666">.</span>fit(X_train, T_train, E_train, init_method<span style="color: #666666">=</span><span style="color: #BA2121">&#39;orthogonal&#39;</span>,
    with_bias <span style="color: #666666">=</span> <span style="color: #008000">True</span>, lr <span style="color: #666666">=</span> <span style="color: #666666">0.8</span>,  tol <span style="color: #666666">=</span> <span style="color: #666666">1e-3</span>,  l2_reg <span style="color: #666666">=</span> <span style="color: #666666">1e-4</span>)

<span style="color: #408080; font-style: italic">#### 5 - Cross Validation / Model Performances</span>
c_index <span style="color: #666666">=</span> concordance_index(svm_model, X_test, T_test, E_test) <span style="color: #408080; font-style: italic">#0.89</span>
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">&#39;C-index: {:.2f}&#39;</span><span style="color: #666666">.</span>format(c_index))
</pre></div>

<p>Because we cannot predict a survival function with <code>KernelSVMModel</code>, let's look at the
risk scores and see how correlated they are to the actual risk scores generated from the Simulation model.</p>
<div class="codehilite" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #408080; font-style: italic">#### 6 - Comparing the model predictions to Actual risk score</span>
<span style="color: #408080; font-style: italic"># Comparing risk scores</span>
svm_risks <span style="color: #666666">=</span> svm_model<span style="color: #666666">.</span>predict_risk(X_test)
actual_risks <span style="color: #666666">=</span> np<span style="color: #666666">.</span>log(sim<span style="color: #666666">.</span>predict_risk(X_test)<span style="color: #666666">.</span>flatten())
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">&quot;corr={:.4f}, p_value={:.5f}&quot;</span><span style="color: #666666">.</span>format(<span style="color: #666666">*</span>pearsonr(svm_risks, actual_risks)))
<span style="color: #408080; font-style: italic"># corr=-0.7519, p_value=0.00000</span>
</pre></div>









            </article>
          </div>
        </div>
      </main>


<footer class="md-footer">

  <div class="md-footer-meta md-typeset">
    <div class="md-footer-meta__inner md-grid">
      <div class="md-footer-copyright">

          <div class="md-footer-copyright__highlight">
            Copyright &copy; 2019 Square Inc.
          </div>



        brought to you by
        <a href="https://squareup.com/us">
        <img src="images/Square_logo.png" alt="Square Logo" title="Square Logo" width=20%, height=20% align="center"  /></a>


      </div>

  <div class="md-footer-social">
    <link rel="stylesheet" href="../assets/fonts/font-awesome.css">

      <a href="https://pysurvival.io/" class="md-footer-social__link fa fa-home"></a>

      <a href="https://github.com/square/pysurvival" class="md-footer-social__link fa fa-github"></a>

  </div>

    </div>
  </div>
</footer>

    </div>

      <script src="../assets/javascripts/application.d9aa80ab.js"></script>

      <script>app.initialize({version:"1.0.4",url:{base:".."}})</script>

        <script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>

        <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-MML-AM_CHTML"></script>

        <script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>

        <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.min.js"></script>

        <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.bundle.min.js"></script>

        <script src="https://cdnjs.cloudflare.com/ajax/libs/chartjs-plugin-annotation/0.5.7/chartjs-plugin-annotation.js"></script>

        <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js"></script>

        <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>


  </body>
</html>
